package com.hhxy.utils;


import com.github.pagehelper.Page;
import com.hhxy.Enum.HttpCode;

import java.io.Serializable;

public class Response<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;
    private String status;
    private String description;
    private String msg;
    private T data;
    private PageData pageData;

    public Response() {
    }

    public Response(HttpCode httpCode){
        this.code = httpCode.getCode();
        this.status = httpCode.getStatus();
        this.description = httpCode.getDescription();
    }

    public Response(HttpCode httpCode,T t){
        this.code = httpCode.getCode();
        this.status = httpCode.getStatus();
        this.description = httpCode.getDescription();
        this.data = t;
        if(data instanceof Page){
            Page<T> page = (Page<T>) data;
            this.pageData = new PageData();
            pageData.setPageNum(page.getPageNum());
            pageData.setPageSize(page.getPageSize());
            pageData.setStartRow(page.getStartRow());
            pageData.setEndRow(page.getEndRow());
            pageData.setTotal(page.getTotal());
            pageData.setPages(page.getPages());
            pageData.setCount(page.isCount());
            pageData.setReasonable(page.getReasonable());
            pageData.setPageSizeZero(page.getPageSizeZero());
            pageData.setCountColumn(page.getCountColumn());
            pageData.setOrderBy(page.getOrderBy());
            pageData.setOrderByOnly(page.isOrderByOnly());
        }
    }

    public Response(HttpCode httpCode,String msg){
        this.code = httpCode.getCode();
        this.status = httpCode.getStatus();
        this.description = httpCode.getDescription();
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public PageData getPageData() {
        return pageData;
    }

    public void setPageData(PageData pageData) {
        this.pageData = pageData;
    }
}
